#coding=utf-8
import datetime
from sqlalchemy import *

metadata = MetaData()

finstrucments = Table('finstrucments', metadata,
    Column('fins_id', Integer, primary_key=True),
    Column('name', String(60), nullable=False),
    Column('type', String(60), nullable=False),
    )

stock = Table('stock', metadata,
    Column('fins_id', Integer, ForeignKey('finstrucments.fins_id'), primary_key=True),
    Column('code', String(10)),
    Column('ipo', Date),
    Column('iprice', Float),
    Column('market', String(60)))

sindex = Table('sindex', metadata,
    Column('fins_id', Integer, ForeignKey('finstrucments.fins_id'), primary_key=True),     
    
    Column('code', String(10)),
    Column('note', String(200)),
    Column('beginning_day', Date))
   
tradedays = Table('tradedays', metadata,
    Column('id', Integer, primary_key=True),
    Column('fins_id', Integer, ForeignKey('finstrucments.fins_id')),
    Column('next_id', Integer, ForeignKey('tradedays.id')),
    
    Column('date', Date),
    )

tradableshare = Table('tradableshare', metadata,
    Column('id', Integer, primary_key=True),
    Column('stock_id', Integer, ForeignKey('stock.fins_id')),
    Column('date', Date),
    Column('quantity', Integer),
    
    Column('created_on', Date, default=datetime.date.today))

fuquanratio = Table('fuquanratio', metadata,
    Column('id', Integer, primary_key=True),
    Column('stock_id', Integer, ForeignKey('stock.fins_id')),
    
    Column('date', Date),
    Column('ratio', Float),
    
    Column('created_on', Date, default=datetime.date.today))
        
price = Table('price', metadata,
    Column('id', Integer, primary_key=True),
    Column('tradeday_id', Integer, ForeignKey('tradedays.id')),
    
    Column('open', Float),
    Column('close', Float),
    Column('highest', Float),
    Column('lowest', Float),
    
    Column('jump', Float),
    Column('change', Float),
    Column('trade_rate', Float),
    Column('fluctuation', Float),
    
    Column('volume', Integer),
    Column('amount', Integer)      
    )
    
deals = Table('deals', metadata,
    Column('id', Integer, primary_key=True),
    Column('tradeday_id', Integer, ForeignKey('tradedays.id')),
    
    Column('time', Time),
    
    Column('price', Float),
    Column('volume', Integer),
    Column('amount', Float),
    
    Column('bors', String(1)),
    )
        
tdcache = Table('tdcache', metadata,
    Column('id', Integer, primary_key=True),
    Column('tradeday_id', Integer, ForeignKey('tradedays.id')),
    
    Column('techname', String(60)),
    Column('int_param', Integer),
    Column('str_param', String(20)),
    Column('boolean_param', Boolean),
    Column('value', Float)
    )

rpcache = Table('rpcache',  metadata,
    Column('id', Integer, primary_key=True),
    Column('stock_id', Integer, ForeignKey('stock.fins_id')),
    Column('time', Time),
    
    Column('now', Float),
    Column('change', Float),
    Column('open', Float),
    Column('jump', Float),
    Column('highest', Float),
    Column('lowest', Float),
    
    Column('volume', Integer),
    Column('amount', Integer)
    )
    
tdstats = Table('tdstats',  metadata, 
    Column('tradeday_id', Integer, ForeignKey('tradedays.id'), primary_key=True),
    
    Column('num_of_trading', Integer),
    Column('num_of_up', Integer),
    Column('num_of_down', Integer),
    Column('num_of_still', Integer),
    
    Column('average_change', Float),
    Column('median_change', Float),
    )

dealstats = Table('dealstats', metadata,
    Column('id', Integer, primary_key=True),
    Column('tradeday_id', Integer, ForeignKey('tradedays.id')),
    
    Column('threshold', Integer),
    Column('direction', String(1)),
    
    Column('buy_num',  Integer),
    Column('buy_money', Integer),
    
    Column('sell_num',  Integer),
    Column('sell_money', Integer),
    
    Column('neutral_num',  Integer),
    Column('neutral_money', Integer),
    
    Column('bs_num',  Integer),
    Column('bs_money', Integer),
    )
    

    
    
    
    
    
    
    
